home *** CD-ROM | disk | FTP | other *** search
/ Aminet 2 / Aminet AMIGA CDROM (1994)(Walnut Creek)[Feb 1994][W.O. 44790-1].iso / Aminet / dev / misc / CWeb31p9b_locale.lha / CWeb / common.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-12-09  |  29.5 KB  |  1,591 lines

  1. /*1:*/
  2. #line 57 "common.w"
  3.  
  4. #line 153 "common.ch"
  5. /*5:*/
  6. #line 101 "common.w"
  7.  
  8. #include <ctype.h>
  9.  
  10. /*:5*//*8:*/
  11. #line 163 "common.w"
  12.  
  13. #include <stdio.h>
  14.  
  15. /*:8*//*22:*/
  16. #line 366 "common.ch"
  17.  
  18. #include <stdlib.h> 
  19. #include <stddef.h> 
  20. #line 470 "common.w"
  21.  
  22. /*:22*//*81:*/
  23. #line 1190 "common.ch"
  24.  
  25. #include <string.h>
  26.  
  27. /*:81*//*86:*/
  28. #line 1259 "common.ch"
  29.  
  30. #ifdef __TURBOC__
  31. #include <alloc.h> 
  32. #include <io.h> 
  33. #endif
  34.  
  35.  
  36. /*:86*//*88:*/
  37. #line 1285 "common.ch"
  38.  
  39. #ifdef _AMIGA
  40. #include <libraries/locale.h>
  41. #include <proto/locale.h>
  42. #include <proto/exec.h>
  43.  
  44. struct Library*LocaleBase;
  45. struct Catalog*catalog;
  46. int i;
  47. #else 
  48. typedef long int LONG;
  49. typedef unsigned char*STRPTR;
  50. #define EXEC_TYPES_H 1 
  51. #endif
  52.  
  53. #define STRINGARRAY 1 
  54. #define get_string(n) AppStrings[n].as_Str 
  55.  
  56. #include "bin/catalogs/cweb.h"
  57.  
  58. /*:88*/
  59. #line 153 "common.ch"
  60.  
  61. /*87:*/
  62. #line 1266 "common.ch"
  63.  
  64. #ifdef __TURBOC__
  65. #define HUGE huge
  66. #else
  67. #define HUGE
  68. #endif
  69.  
  70.  
  71. /*:87*/
  72. #line 154 "common.ch"
  73.  
  74. #line 59 "common.w"
  75. #define ctangle 0
  76. #define cweave 1 \
  77.  
  78. #define and_and 04
  79. #define lt_lt 020
  80. #define gt_gt 021
  81. #define plus_plus 013
  82. #define minus_minus 01
  83. #define minus_gt 031
  84. #define not_eq 032
  85. #define lt_eq 034
  86. #define gt_eq 035
  87. #define eq_eq 036
  88. #define or_or 037
  89. #define dot_dot_dot 016
  90. #define colon_colon 06
  91. #define period_ast 026
  92. #define minus_gt_ast 027 \
  93.  
  94. #define buf_size 100
  95. #define long_buf_size 500
  96. #define xisspace(c) (isspace(c) &&((unsigned char) c<0200) ) 
  97. #define xisupper(c) (isupper(c) &&((unsigned char) c<0200) )  \
  98.  
  99. #define max_include_depth 10 \
  100.  \
  101.  
  102. #define max_file_name_length 256 \
  103.  
  104. #define cur_file file[include_depth]
  105. #define cur_file_name file_name[include_depth]
  106. #define cur_line line[include_depth]
  107. #define web_file file[0]
  108. #define web_file_name file_name[0] \
  109.  
  110. #define lines_dont_match (change_limit-change_buffer!=limit-buffer|| \
  111. strncmp(buffer,change_buffer,(size_t) (limit-buffer) ) )  \
  112.  
  113. #define if_section_start_make_pending(b) {*limit= '!'; \
  114. for(loc= buffer;xisspace(*loc) ;loc++) ; \
  115. *limit= ' '; \
  116. if(*loc=='@'&&(xisspace(*(loc+1) ) ||*(loc+1) =='*') ) change_pending= b; \
  117. } \
  118.  
  119. #define max_sections 2000 \
  120.  \
  121.  
  122. #define PATH_SEPARATOR ','
  123. #define DIR_SEPARATOR '/'
  124. #define DEVICE_SEPARATOR ':' \
  125.  
  126. #define too_long() {include_depth--; \
  127. err_print(get_string(MSG_ERROR_CO22) ) ;goto restart;} \
  128.  
  129. #define max_bytes 90000 \
  130.  
  131. #define max_names 4000 \
  132.  \
  133.  
  134. #define length(c) (size_t) ((c+1) ->byte_start-(c) ->byte_start)  \
  135.  
  136. #define print_id(c) term_write((c) ->byte_start,length((c) ) )  \
  137.  
  138. #define hash_size 353 \
  139.  
  140. #define llink link
  141. #define rlink dummy.Rlink
  142. #define root name_dir->rlink \
  143.  \
  144.  
  145. #define first_chunk(p) ((p) ->byte_start+2) 
  146. #define prefix_length(p) (int) ((unsigned char) *((p) ->byte_start) *256+ \
  147. (unsigned char) *((p) ->byte_start+1) ) 
  148. #define set_prefix_length(p,m) (*((p) ->byte_start) = (m) /256, \
  149. *((p) ->byte_start+1) = (m) %256)  \
  150.  
  151. #define less 0
  152. #define equal 1
  153. #define greater 2
  154. #define prefix 3
  155. #define extension 4 \
  156.  
  157. #define bad_extension 5 \
  158.  \
  159.  
  160. #define spotless 0
  161. #define harmless_message 1
  162. #define error_message 2
  163. #define fatal_message 3
  164. #define mark_harmless {if(history==spotless) history= harmless_message;}
  165. #define mark_error history= error_message \
  166.  
  167. #define RETURN_OK 0
  168. #define RETURN_WARN 5
  169. #define RETURN_ERROR 10
  170. #define RETURN_FAIL 20 \
  171.  
  172. #define confusion(s) fatal(get_string(MSG_FATAL_CO66) ,s)  \
  173.  \
  174.  
  175. #define show_banner flags['b']
  176. #define show_progress flags['p']
  177. #define show_stats flags['s']
  178. #define show_happiness flags['h']
  179. #define use_amiga_keywords flags['a']
  180. #define use_german_macros flags['g']
  181. #define indent_param_decl flags['i']
  182. #define order_decl_stmt flags['o'] \
  183.  
  184. #define update_terminal fflush(stdout)  \
  185.  
  186. #define new_line putchar('\n') 
  187. #define putxchar putchar
  188. #define term_write(a,b) fflush(stdout) ,fwrite(a,sizeof(char) ,b,stdout) 
  189. #define C_printf(c,a) fprintf(C_file,c,a) 
  190. #define C_putc(c) putc(c,C_file)  \
  191.  \
  192.  
  193. #define MAXPATHLENGTH 4095
  194. #define CWEBINPUTS ",CWeb:,CWeb:include,CWeb:inputs" \
  195.  
  196.  
  197. #line 59 "common.w"
  198.  
  199. /*2:*/
  200. #line 72 "common.w"
  201.  
  202. typedef short boolean;
  203. boolean program;
  204.  
  205. /*:2*//*7:*/
  206. #line 157 "common.w"
  207.  
  208. char buffer[long_buf_size];
  209. char*buffer_end= buffer+buf_size-2;
  210. char*limit= buffer;
  211. char*loc= buffer;
  212.  
  213. /*:7*//*10:*/
  214. #line 212 "common.w"
  215.  
  216. int include_depth;
  217. FILE*file[max_include_depth];
  218. FILE*change_file;
  219. char file_name[max_include_depth][max_file_name_length];
  220.  
  221. char change_file_name[max_file_name_length];
  222. char alt_web_file_name[max_file_name_length];
  223. int line[max_include_depth];
  224. int change_line;
  225. int change_depth;
  226. boolean input_has_ended;
  227. boolean changing;
  228. boolean web_file_open= 0;
  229.  
  230. /*:10*//*20:*/
  231. #line 416 "common.w"
  232.  
  233. #line 303 "common.ch"
  234. typedef unsigned char eight_bits;
  235. typedef unsigned short sixteen_bits;
  236. #line 418 "common.w"
  237. sixteen_bits section_count;
  238. boolean changed_section[max_sections];
  239. boolean change_pending;
  240.  
  241. boolean print_where= 0;
  242.  
  243. /*:20*//*27:*/
  244. #line 586 "common.w"
  245.  
  246. typedef struct name_info{
  247. #line 469 "common.ch"
  248. char HUGE*byte_start;
  249. #line 589 "common.w"
  250. /*31:*/
  251. #line 623 "common.w"
  252.  
  253. #line 520 "common.ch"
  254. struct name_info HUGE*link;
  255. #line 625 "common.w"
  256.  
  257. /*:31*//*40:*/
  258. #line 722 "common.w"
  259.  
  260. union{
  261. #line 574 "common.ch"
  262. struct name_info HUGE*Rlink;
  263.  
  264. #line 726 "common.w"
  265. char Ilk;
  266. }dummy;
  267.  
  268. /*:40*//*55:*/
  269. #line 847 "common.ch"
  270.  
  271. #line 848 "common.ch"
  272. void HUGE*equiv_or_xref;
  273. #line 1056 "common.w"
  274.  
  275. /*:55*/
  276. #line 589 "common.w"
  277.  
  278. }name_info;
  279. #line 479 "common.ch"
  280. typedef name_info HUGE*name_pointer;
  281. #ifdef __TURBOC__
  282. char HUGE*byte_mem;
  283. char HUGE*byte_mem_end;
  284. name_info HUGE*name_dir;
  285. name_pointer name_dir_end;
  286. #else
  287. char byte_mem[max_bytes];
  288. char*byte_mem_end= byte_mem+max_bytes-1;
  289. name_info name_dir[max_names];
  290. name_pointer name_dir_end= name_dir+max_names-1;
  291. #endif
  292. #line 596 "common.w"
  293.  
  294. /*:27*//*29:*/
  295. #line 609 "common.w"
  296.  
  297. name_pointer name_ptr;
  298. #line 502 "common.ch"
  299. char HUGE*byte_ptr;
  300. #line 612 "common.w"
  301.  
  302. /*:29*//*32:*/
  303. #line 636 "common.w"
  304.  
  305. typedef name_pointer*hash_pointer;
  306. name_pointer hash[hash_size];
  307. hash_pointer hash_end= hash+hash_size-1;
  308. hash_pointer h;
  309.  
  310. #line 527 "common.ch"
  311. /*:32*//*56:*/
  312. #line 1074 "common.w"
  313.  
  314. int history= spotless;
  315.  
  316. /*:56*//*67:*/
  317. #line 1212 "common.w"
  318.  
  319. int argc;
  320. char**argv;
  321. char C_file_name[max_file_name_length];
  322. char tex_file_name[max_file_name_length];
  323. char idx_file_name[max_file_name_length];
  324. char scn_file_name[max_file_name_length];
  325. #line 1048 "common.ch"
  326. boolean flags[256];
  327. #line 1220 "common.w"
  328.  
  329. /*:67*//*77:*/
  330. #line 1366 "common.w"
  331.  
  332. FILE*C_file;
  333. FILE*tex_file;
  334. FILE*idx_file;
  335. FILE*scn_file;
  336. FILE*active_file;
  337.  
  338. /*:77*/
  339. #line 60 "common.w"
  340.  
  341. /*3:*/
  342. #line 82 "common.w"
  343. int phase;
  344.  
  345. /*:3*//*11:*/
  346. #line 238 "common.w"
  347.  
  348. char change_buffer[buf_size];
  349. char*change_limit;
  350.  
  351. /*:11*//*83:*/
  352. #line 1223 "common.ch"
  353.  
  354. char include_path[MAXPATHLENGTH+1]= CWEBINPUTS;
  355. char*p,*path_prefix,*next_path_prefix;
  356.  
  357. /*:83*/
  358. #line 61 "common.w"
  359.  
  360. /*33:*/
  361. #line 527 "common.ch"
  362.  
  363. extern int names_match(name_pointer,char*,int,eight_bits);
  364. #line 644 "common.w"
  365.  
  366. /*:33*//*38:*/
  367. #line 558 "common.ch"
  368.  
  369. #line 559 "common.ch"
  370. extern void init_p(name_pointer,eight_bits);
  371. #line 697 "common.w"
  372.  
  373. /*:38*//*46:*/
  374. #line 662 "common.ch"
  375.  
  376. #line 663 "common.ch"
  377. extern void init_node(name_pointer);
  378. #line 846 "common.w"
  379.  
  380. /*:46*//*53:*/
  381. #line 802 "common.ch"
  382.  
  383. static int section_name_cmp(char**,int,name_pointer);
  384. #line 1011 "common.w"
  385.  
  386. /*:53*//*57:*/
  387. #line 862 "common.ch"
  388.  
  389. #line 863 "common.ch"
  390. extern void err_print(char*);
  391. #line 1086 "common.w"
  392.  
  393. /*:57*//*60:*/
  394. #line 890 "common.ch"
  395.  
  396. #line 891 "common.ch"
  397. extern int wrap_up(void);
  398. extern void print_stats(void);
  399. #line 1135 "common.w"
  400.  
  401. #line 915 "common.ch"
  402. /*:60*//*63:*/
  403. #line 965 "common.ch"
  404.  
  405. #line 966 "common.ch"
  406. extern void fatal(char*,char*);
  407. extern void overflow(char*);
  408. #line 1167 "common.w"
  409.  
  410. /*:63*//*69:*/
  411. #line 1077 "common.ch"
  412.  
  413. #line 1078 "common.ch"
  414. static void scan_args(void);
  415. #line 1245 "common.w"
  416.  
  417. /*:69*//*84:*/
  418. #line 1241 "common.ch"
  419.  
  420. #ifdef __TURBOC__
  421. extern void far*allocsafe(unsigned long,unsigned long);
  422. #endif
  423.  
  424.  
  425. /*:84*//*91:*/
  426. #line 1336 "common.ch"
  427.  
  428. int get_line(void);
  429. name_pointer add_section_name(name_pointer par,int c,
  430. char*first,char*last,int ispref);
  431. name_pointer id_lookup(char*first,char*last,char t);
  432. name_pointer section_lookup(char*first,char*last,int ispref);
  433. void check_complete(void);
  434. void common_init(void);
  435. void extend_section_name(name_pointer p,char*first,char*last,int ispref);
  436. void print_prefix_name(name_pointer);
  437. void print_section_name(name_pointer);
  438. void reset_input(void);
  439. void sprint_section_name(char*,name_pointer);
  440.  
  441. /*:91*//*92:*/
  442. #line 1352 "common.ch"
  443.  
  444. static boolean set_path(char*ptr,char*override);
  445. static int input_ln(FILE*fp);
  446. static int web_strcmp(char HUGE*j,int j_len,char HUGE*k,int k_len);
  447. static void check_change(void);
  448. static void prime_the_change_buffer(void);
  449.  
  450. /*:92*/
  451. #line 62 "common.w"
  452.  
  453.  
  454. /*:1*//*4:*/
  455. #line 88 "common.w"
  456.  
  457. #line 166 "common.ch"
  458. void common_init(void)
  459. {
  460. /*30:*/
  461. #line 613 "common.w"
  462.  
  463. #line 508 "common.ch"
  464. #ifdef __TURBOC__
  465. byte_mem= allocsafe(max_bytes,sizeof(*byte_mem));
  466. byte_mem_end= byte_mem+max_bytes-1;
  467. name_dir= allocsafe(max_names,sizeof(*name_dir));
  468. name_dir_end= name_dir+max_names-1;
  469. #endif
  470. name_dir->byte_start= byte_ptr= byte_mem;
  471. #line 615 "common.w"
  472. name_ptr= name_dir+1;
  473. name_ptr->byte_start= byte_mem;
  474.  
  475. /*:30*//*34:*/
  476. #line 647 "common.w"
  477.  
  478. for(h= hash;h<=hash_end;*h++= NULL);
  479.  
  480. /*:34*//*41:*/
  481. #line 729 "common.w"
  482.  
  483. root= NULL;
  484.  
  485. /*:41*/
  486. #line 168 "common.ch"
  487. ;
  488. /*89:*/
  489. #line 1310 "common.ch"
  490.  
  491. #ifdef _AMIGA
  492. if(LocaleBase= OpenLibrary("locale.library",38L)){
  493. if(catalog= OpenCatalog(NULL,"cweb.catalog",
  494. OC_BuiltInLanguage,"english",TAG_DONE)){
  495. for(i= MSG_ERROR_CO9;i<=MSG_STATS_CW248_6;++i)
  496. AppStrings[i].as_Str= GetCatalogStr(catalog,i,AppStrings[i].as_Str);
  497. }
  498. }
  499. #endif
  500.  
  501. /*:89*/
  502. #line 169 "common.ch"
  503. ;
  504. /*68:*/
  505. #line 1056 "common.ch"
  506.  
  507. #line 1057 "common.ch"
  508. show_banner= show_happiness= show_progress= 1;
  509. #ifdef _AMIGA
  510. use_amiga_keywords= 
  511. #endif
  512. use_german_macros= indent_param_decl= order_decl_stmt= 1;
  513. #line 1227 "common.w"
  514.  
  515. /*:68*/
  516. #line 170 "common.ch"
  517. ;
  518. /*78:*/
  519. #line 1373 "common.w"
  520.  
  521. scan_args();
  522. if(program==ctangle){
  523. if((C_file= fopen(C_file_name,"w"))==NULL)
  524. #line 1159 "common.ch"
  525. fatal(get_string(MSG_FATAL_CO78),C_file_name);
  526. #line 1378 "common.w"
  527.  
  528. }
  529. else{
  530. if((tex_file= fopen(tex_file_name,"w"))==NULL)
  531. #line 1166 "common.ch"
  532. fatal(get_string(MSG_FATAL_CO78),tex_file_name);
  533. #line 1383 "common.w"
  534. }
  535.  
  536. /*:78*/
  537. #line 171 "common.ch"
  538. ;
  539. }
  540. #line 96 "common.w"
  541.  
  542. /*:4*//*9:*/
  543. #line 170 "common.w"
  544.  
  545. #line 186 "common.ch"
  546. static int input_ln(FILE*fp)
  547.  
  548. #line 173 "common.w"
  549. {
  550. register int c= EOF;
  551. register char*k;
  552. if(feof(fp))return(0);
  553. limit= k= buffer;
  554. while(k<=buffer_end&&(c= getc(fp))!=EOF&&c!='\n')
  555. if((*(k++)= c)!=' ')limit= k;
  556. if(k>buffer_end)
  557. if((c= getc(fp))!=EOF&&c!='\n'){
  558. #line 194 "common.ch"
  559. ungetc(c,fp);loc= buffer;err_print(get_string(MSG_ERROR_CO9));
  560. #line 183 "common.w"
  561.  
  562. }
  563. if(c==EOF&&limit==buffer)return(0);
  564.  
  565. return(1);
  566. }
  567.  
  568. /*:9*//*12:*/
  569. #line 249 "common.w"
  570.  
  571. #line 218 "common.ch"
  572. static void prime_the_change_buffer(void)
  573. #line 252 "common.w"
  574. {
  575. change_limit= change_buffer;
  576. /*13:*/
  577. #line 263 "common.w"
  578.  
  579. while(1){
  580. change_line++;
  581. if(!input_ln(change_file))return;
  582. if(limit<buffer+2)continue;
  583. if(buffer[0]!='@')continue;
  584. if(xisupper(buffer[1]))buffer[1]= tolower(buffer[1]);
  585. if(buffer[1]=='x')break;
  586. if(buffer[1]=='y'||buffer[1]=='z'||buffer[1]=='i'){
  587. loc= buffer+2;
  588. #line 225 "common.ch"
  589. err_print(get_string(MSG_ERROR_CO13));
  590. #line 274 "common.w"
  591.  
  592. }
  593. }
  594.  
  595. /*:13*/
  596. #line 254 "common.w"
  597. ;
  598. /*14:*/
  599. #line 280 "common.w"
  600.  
  601. do{
  602. change_line++;
  603. if(!input_ln(change_file)){
  604. #line 232 "common.ch"
  605. err_print(get_string(MSG_ERROR_CO14));
  606. #line 285 "common.w"
  607.  
  608. return;
  609. }
  610. }while(limit==buffer);
  611.  
  612. /*:14*/
  613. #line 255 "common.w"
  614. ;
  615. /*15:*/
  616. #line 290 "common.w"
  617.  
  618. {
  619. #line 239 "common.ch"
  620. change_limit= change_buffer+(ptrdiff_t)(limit-buffer);
  621. strncpy(change_buffer,buffer,(size_t)(limit-buffer+1));
  622. #line 294 "common.w"
  623. }
  624.  
  625. /*:15*/
  626. #line 256 "common.w"
  627. ;
  628. }
  629.  
  630. /*:12*//*16:*/
  631. #line 318 "common.w"
  632.  
  633. #line 247 "common.ch"
  634. static void check_change(void)
  635. #line 321 "common.w"
  636. {
  637. int n= 0;
  638. if(lines_dont_match)return;
  639. change_pending= 0;
  640. if(!changed_section[section_count]){
  641. if_section_start_make_pending(1);
  642. if(!change_pending)changed_section[section_count]= 1;
  643. }
  644. while(1){
  645. changing= 1;print_where= 1;change_line++;
  646. if(!input_ln(change_file)){
  647. #line 254 "common.ch"
  648. err_print(get_string(MSG_ERROR_CO16_1));
  649. #line 333 "common.w"
  650.  
  651. change_limit= change_buffer;changing= 0;
  652. return;
  653. }
  654. if(limit>buffer+1&&buffer[0]=='@'){
  655. if(xisupper(buffer[1]))buffer[1]= tolower(buffer[1]);
  656. /*17:*/
  657. #line 356 "common.w"
  658.  
  659. if(buffer[1]=='x'||buffer[1]=='z'){
  660. #line 268 "common.ch"
  661. loc= buffer+2;err_print(get_string(MSG_ERROR_CO17_1));
  662. #line 359 "common.w"
  663.  
  664. }
  665. else if(buffer[1]=='y'){
  666. if(n>0){
  667. loc= buffer+2;
  668. printf("\n! Hmm... %d ",n);
  669. #line 275 "common.ch"
  670. err_print(get_string(MSG_ERROR_CO17_2));
  671. #line 366 "common.w"
  672.  
  673. }
  674. change_depth= include_depth;
  675. return;
  676. }
  677.  
  678. /*:17*/
  679. #line 340 "common.w"
  680. ;
  681. }
  682. /*15:*/
  683. #line 290 "common.w"
  684.  
  685. {
  686. #line 239 "common.ch"
  687. change_limit= change_buffer+(ptrdiff_t)(limit-buffer);
  688. strncpy(change_buffer,buffer,(size_t)(limit-buffer+1));
  689. #line 294 "common.w"
  690. }
  691.  
  692. /*:15*/
  693. #line 342 "common.w"
  694. ;
  695. changing= 0;cur_line++;
  696. while(!input_ln(cur_file)){
  697. if(include_depth==0){
  698. #line 261 "common.ch"
  699. err_print(get_string(MSG_ERROR_CO16_2));
  700. #line 347 "common.w"
  701.  
  702. input_has_ended= 1;return;
  703. }
  704. include_depth--;cur_line++;
  705. }
  706. if(lines_dont_match)n++;
  707. }
  708. }
  709.  
  710. /*:16*//*18:*/
  711. #line 376 "common.w"
  712.  
  713. #line 282 "common.ch"
  714. void reset_input(void)
  715. #line 379 "common.w"
  716. {
  717. limit= buffer;loc= buffer+1;buffer[0]= ' ';
  718. /*19:*/
  719. #line 391 "common.w"
  720.  
  721. if((web_file= fopen(web_file_name,"r"))==NULL){
  722. strcpy(web_file_name,alt_web_file_name);
  723. if((web_file= fopen(web_file_name,"r"))==NULL)
  724. #line 289 "common.ch"
  725. fatal(get_string(MSG_FATAL_CO19_1),web_file_name);
  726. #line 396 "common.w"
  727. }
  728.  
  729.  
  730. web_file_open= 1;
  731. if((change_file= fopen(change_file_name,"r"))==NULL)
  732. #line 296 "common.ch"
  733. fatal(get_string(MSG_FATAL_CO19_2),change_file_name);
  734. #line 402 "common.w"
  735.  
  736. /*:19*/
  737. #line 381 "common.w"
  738. ;
  739. include_depth= 0;cur_line= 0;change_line= 0;
  740. change_depth= include_depth;
  741. changing= 1;prime_the_change_buffer();changing= !changing;
  742. limit= buffer;loc= buffer+1;buffer[0]= ' ';input_has_ended= 0;
  743. }
  744.  
  745. /*:18*//*21:*/
  746. #line 424 "common.w"
  747.  
  748. #line 310 "common.ch"
  749. int get_line(void)
  750. #line 426 "common.w"
  751. {
  752. restart:
  753. if(changing&&include_depth==change_depth)
  754. /*25:*/
  755. #line 529 "common.w"
  756. {
  757. change_line++;
  758. if(!input_ln(change_file)){
  759. #line 435 "common.ch"
  760. err_print(get_string(MSG_ERROR_CO25_1));
  761. #line 533 "common.w"
  762.  
  763. buffer[0]= '@';buffer[1]= 'z';limit= buffer+2;
  764. }
  765. if(limit>buffer){
  766. if(change_pending){
  767. if_section_start_make_pending(0);
  768. if(change_pending){
  769. changed_section[section_count]= 1;change_pending= 0;
  770. }
  771. }
  772. *limit= ' ';
  773. if(buffer[0]=='@'){
  774. if(xisupper(buffer[1]))buffer[1]= tolower(buffer[1]);
  775. if(buffer[1]=='x'||buffer[1]=='y'){
  776. loc= buffer+2;
  777. #line 442 "common.ch"
  778. err_print(get_string(MSG_ERROR_CO25_2));
  779. #line 549 "common.w"
  780.  
  781. }
  782. else if(buffer[1]=='z'){
  783. prime_the_change_buffer();changing= !changing;print_where= 1;
  784. }
  785. }
  786. }
  787. }
  788.  
  789. /*:25*/
  790. #line 429 "common.w"
  791. ;
  792. if(!changing||include_depth>change_depth){
  793. /*24:*/
  794. #line 512 "common.w"
  795. {
  796. cur_line++;
  797. while(!input_ln(cur_file)){
  798. print_where= 1;
  799. if(include_depth==0){input_has_ended= 1;break;}
  800. else{
  801. fclose(cur_file);include_depth--;
  802. if(changing&&include_depth==change_depth)break;
  803. cur_line++;
  804. }
  805. }
  806. if(!changing&&!input_has_ended)
  807. if(limit-buffer==change_limit-change_buffer)
  808. if(buffer[0]==change_buffer[0])
  809. if(change_limit>change_buffer)check_change();
  810. }
  811.  
  812. /*:24*/
  813. #line 431 "common.w"
  814. ;
  815. if(changing&&include_depth==change_depth)goto restart;
  816. }
  817. loc= buffer;*limit= ' ';
  818. if(*buffer=='@'&&(*(buffer+1)=='i'||*(buffer+1)=='I')){
  819. loc= buffer+2;
  820. while(loc<=limit&&(*loc==' '||*loc=='\t'||*loc=='"'))loc++;
  821. if(loc>=limit){
  822. #line 317 "common.ch"
  823. err_print(get_string(MSG_ERROR_CO21_1));
  824. #line 440 "common.w"
  825.  
  826. goto restart;
  827. }
  828. if(include_depth>=max_include_depth-1){
  829. #line 324 "common.ch"
  830. err_print(get_string(MSG_ERROR_CO21_2));
  831. #line 445 "common.w"
  832.  
  833. goto restart;
  834. }
  835. include_depth++;
  836. /*23:*/
  837. #line 471 "common.w"
  838. {
  839. char temp_file_name[max_file_name_length];
  840. char*cur_file_name_end= cur_file_name+max_file_name_length-1;
  841. char*k= cur_file_name,*kk;
  842. int l;
  843.  
  844. while(*loc!=' '&&*loc!='\t'&&*loc!='"'&&k<=cur_file_name_end)*k++= *loc++;
  845. if(k>cur_file_name_end)too_long();
  846.  
  847. *k= '\0';
  848. if((cur_file= fopen(cur_file_name,"r"))!=NULL){
  849. cur_line= 0;print_where= 1;
  850. goto restart;
  851. }
  852. #line 401 "common.ch"
  853. if(0==set_path(include_path,getenv("CWEBINPUTS"))){
  854. include_depth--;goto restart;
  855. }
  856. path_prefix= include_path;
  857. while(path_prefix){
  858. for(kk= temp_file_name,p= path_prefix,l= 0;
  859. p&&*p&&*p!=PATH_SEPARATOR;
  860. *kk++= *p++,l++);
  861. if(path_prefix&&*path_prefix&&*path_prefix!=PATH_SEPARATOR&&
  862. *--p!=DEVICE_SEPARATOR&&*p!=DIR_SEPARATOR){
  863. *kk++= DIR_SEPARATOR;l++;
  864. }
  865. if(k+l+2>=cur_file_name_end)too_long();
  866. strcpy(kk,cur_file_name);
  867. if(cur_file= fopen(temp_file_name,"r")){
  868. cur_line= 0;print_where= 1;goto restart;
  869. }
  870. if(next_path_prefix= strchr(path_prefix,PATH_SEPARATOR))
  871. path_prefix= next_path_prefix+1;
  872. else break;
  873. }
  874. #line 428 "common.ch"
  875. include_depth--;err_print(get_string(MSG_ERROR_CO23));goto restart;
  876. #line 510 "common.w"
  877. }
  878.  
  879. /*:23*/
  880. #line 449 "common.w"
  881. ;
  882. }
  883. return(!input_has_ended);
  884. }
  885.  
  886. #line 347 "common.ch"
  887. /*:21*//*26:*/
  888. #line 561 "common.w"
  889.  
  890. #line 453 "common.ch"
  891. void check_complete(void){
  892. if(change_limit!=change_buffer){
  893. strncpy(buffer,change_buffer,(size_t)(change_limit-change_buffer+1));
  894. limit= buffer+(ptrdiff_t)(change_limit-change_buffer);
  895. #line 567 "common.w"
  896. changing= 1;change_depth= include_depth;loc= buffer;
  897. #line 463 "common.ch"
  898. err_print(get_string(MSG_ERROR_CO26));
  899. #line 569 "common.w"
  900.  
  901. }
  902. }
  903.  
  904. /*:26*//*35:*/
  905. #line 652 "common.w"
  906.  
  907. #line 540 "common.ch"
  908. name_pointer id_lookup(char*first,char*last,char t)
  909.  
  910.  
  911.  
  912.  
  913. #line 658 "common.w"
  914. {
  915. char*i= first;
  916. int h;
  917. int l;
  918. name_pointer p;
  919. if(last==NULL)for(last= first;*last!='\0';last++);
  920. #line 551 "common.ch"
  921. l= (int)(last-first);
  922. #line 665 "common.w"
  923. /*36:*/
  924. #line 675 "common.w"
  925.  
  926. h= (unsigned char)*i;
  927. while(++i<last)h= (h+h+(int)((unsigned char)*i))%hash_size;
  928.  
  929.  
  930. /*:36*/
  931. #line 665 "common.w"
  932. ;
  933. /*37:*/
  934. #line 683 "common.w"
  935.  
  936. p= hash[h];
  937. while(p&&!names_match(p,first,l,t))p= p->link;
  938. if(p==NULL){
  939. p= name_ptr;
  940. p->link= hash[h];hash[h]= p;
  941. }
  942.  
  943. /*:37*/
  944. #line 666 "common.w"
  945. ;
  946. if(p==name_ptr)/*39:*/
  947. #line 698 "common.w"
  948. {
  949. #line 567 "common.ch"
  950. if(byte_ptr+l>byte_mem_end)overflow(get_string(MSG_OVERFLOW_CO39_1));
  951. if(name_ptr>=name_dir_end)overflow(get_string(MSG_OVERFLOW_CO39_2));
  952. #line 701 "common.w"
  953. strncpy(byte_ptr,first,l);
  954. (++name_ptr)->byte_start= byte_ptr+= l;
  955. if(program==cweave)init_p(p,t);
  956. }
  957.  
  958. /*:39*/
  959. #line 667 "common.w"
  960. ;
  961. return(p);
  962. }
  963.  
  964. /*:35*//*42:*/
  965. #line 756 "common.w"
  966.  
  967. #line 582 "common.ch"
  968. void print_section_name(name_pointer p)
  969. #line 760 "common.w"
  970. {
  971. #line 588 "common.ch"
  972. char HUGE*ss;
  973. char HUGE*s= first_chunk(p);
  974. #line 762 "common.w"
  975. name_pointer q= p+1;
  976. while(p!=name_dir){
  977. ss= (p+1)->byte_start-1;
  978. if(*ss==' '&&ss>=s){
  979. #line 597 "common.ch"
  980. term_write(s,(size_t)(ss-s));p= q->link;q= p;
  981. }else{
  982. term_write(s,(size_t)(ss+1-s));p= name_dir;q= NULL;
  983. #line 769 "common.w"
  984. }
  985. s= p->byte_start;
  986. }
  987. if(q)term_write("...",3);
  988. }
  989.  
  990. /*:42*//*43:*/
  991. #line 775 "common.w"
  992.  
  993. #line 608 "common.ch"
  994. void sprint_section_name(char*dest,name_pointer p)
  995. #line 780 "common.w"
  996. {
  997. #line 614 "common.ch"
  998. char HUGE*ss;
  999. char HUGE*s= first_chunk(p);
  1000. #line 782 "common.w"
  1001. name_pointer q= p+1;
  1002. while(p!=name_dir){
  1003. ss= (p+1)->byte_start-1;
  1004. if(*ss==' '&&ss>=s){
  1005. p= q->link;q= p;
  1006. }else{
  1007. ss++;p= name_dir;
  1008. }
  1009. #line 623 "common.ch"
  1010. strncpy(dest,s,(size_t)(ss-s)),dest+= ss-s;
  1011. #line 791 "common.w"
  1012. s= p->byte_start;
  1013. }
  1014. *dest= '\0';
  1015. }
  1016.  
  1017. /*:43*//*44:*/
  1018. #line 796 "common.w"
  1019.  
  1020. #line 631 "common.ch"
  1021. void print_prefix_name(name_pointer p)
  1022. #line 800 "common.w"
  1023. {
  1024. #line 637 "common.ch"
  1025. char HUGE*s= first_chunk(p);
  1026. #line 802 "common.w"
  1027. int l= prefix_length(p);
  1028. term_write(s,l);
  1029. if(s+l<(p+1)->byte_start)term_write("...",3);
  1030. }
  1031.  
  1032. /*:44*//*45:*/
  1033. #line 817 "common.w"
  1034.  
  1035. #line 647 "common.ch"
  1036. static int web_strcmp(char HUGE*j,int j_len,char HUGE*k,int k_len)
  1037.  
  1038.  
  1039.  
  1040.  
  1041.  
  1042. {
  1043. char HUGE*j1= j+j_len;
  1044. char HUGE*k1= k+k_len;
  1045. #line 823 "common.w"
  1046. while(k<k1&&j<j1&&*j==*k)k++,j++;
  1047. if(k==k1)if(j==j1)return equal;
  1048. else return extension;
  1049. else if(j==j1)return prefix;
  1050. else if(*j<*k)return less;
  1051. else return greater;
  1052. }
  1053.  
  1054. /*:45*//*47:*/
  1055. #line 847 "common.w"
  1056.  
  1057. #line 675 "common.ch"
  1058. name_pointer add_section_name(name_pointer par,int c,
  1059. char*first,char*last,int ispref)
  1060.  
  1061.  
  1062.  
  1063.  
  1064.  
  1065.  
  1066. #line 855 "common.w"
  1067. {
  1068. name_pointer p= name_ptr;
  1069. #line 692 "common.ch"
  1070. char HUGE*s= first_chunk(p);
  1071. int name_len= (int)(last-first)+ispref;
  1072. if(s+name_len>byte_mem_end)overflow(get_string(MSG_OVERFLOW_CO39_1));
  1073. if(name_ptr+1>=name_dir_end)overflow(get_string(MSG_OVERFLOW_CO39_2));
  1074. #line 861 "common.w"
  1075. (++name_ptr)->byte_start= byte_ptr= s+name_len;
  1076. if(ispref){
  1077. *(byte_ptr-1)= ' ';
  1078. name_len--;
  1079. name_ptr->link= name_dir;
  1080. (++name_ptr)->byte_start= byte_ptr;
  1081. }
  1082. set_prefix_length(p,name_len);
  1083. strncpy(s,first,name_len);
  1084. p->llink= NULL;
  1085. p->rlink= NULL;
  1086. init_node(p);
  1087. return par==NULL?(root= p):c==less?(par->llink= p):(par->rlink= p);
  1088. }
  1089.  
  1090. /*:47*//*48:*/
  1091. #line 876 "common.w"
  1092.  
  1093. #line 706 "common.ch"
  1094. void extend_section_name(name_pointer p,char*first,char*last,int ispref)
  1095.  
  1096.  
  1097.  
  1098.  
  1099. #line 883 "common.w"
  1100. {
  1101. #line 720 "common.ch"
  1102. char HUGE*s;
  1103. name_pointer q= p+1;
  1104. int name_len= (int)(last-first)+ispref;
  1105. if(name_ptr>=name_dir_end)overflow(get_string(MSG_OVERFLOW_CO39_2));
  1106. #line 888 "common.w"
  1107. while(q->link!=name_dir)q= q->link;
  1108. q->link= name_ptr;
  1109. s= name_ptr->byte_start;
  1110. name_ptr->link= name_dir;
  1111. #line 730 "common.ch"
  1112. if(s+name_len>byte_mem_end)overflow(get_string(MSG_OVERFLOW_CO39_1));
  1113. #line 893 "common.w"
  1114. (++name_ptr)->byte_start= byte_ptr= s+name_len;
  1115. strncpy(s,first,name_len);
  1116. if(ispref)*(byte_ptr-1)= ' ';
  1117. }
  1118.  
  1119. /*:48*//*49:*/
  1120. #line 904 "common.w"
  1121.  
  1122. #line 746 "common.ch"
  1123. name_pointer section_lookup(char*first,char*last,int ispref)
  1124.  
  1125.  
  1126.  
  1127. #line 909 "common.w"
  1128. {
  1129. int c= 0;
  1130. name_pointer p= root;
  1131. name_pointer q= NULL;
  1132. name_pointer r= NULL;
  1133. name_pointer par= NULL;
  1134.  
  1135. #line 755 "common.ch"
  1136. int name_len= (int)(last-first)+1;
  1137. #line 917 "common.w"
  1138. /*50:*/
  1139. #line 928 "common.w"
  1140.  
  1141. while(p){
  1142. c= web_strcmp(first,name_len,first_chunk(p),prefix_length(p));
  1143. if(c==less||c==greater){
  1144. if(r==NULL)
  1145. par= p;
  1146. p= (c==less?p->llink:p->rlink);
  1147. }else{
  1148. if(r!=NULL){
  1149. #line 765 "common.ch"
  1150. printf(get_string(MSG_ERROR_CO50_1));
  1151.  
  1152. print_prefix_name(p);
  1153. printf(get_string(MSG_ERROR_CO50_2));
  1154. #line 941 "common.w"
  1155. print_prefix_name(r);
  1156. err_print(">");
  1157. return name_dir;
  1158. }
  1159. r= p;
  1160. p= p->llink;
  1161. q= r->rlink;
  1162. }
  1163. if(p==NULL)
  1164. p= q,q= NULL;
  1165. }
  1166.  
  1167. /*:50*/
  1168. #line 918 "common.w"
  1169. ;
  1170. /*51:*/
  1171. #line 953 "common.w"
  1172.  
  1173. if(r==NULL)
  1174. return add_section_name(par,c,first,last+1,ispref);
  1175.  
  1176. /*:51*/
  1177. #line 919 "common.w"
  1178. ;
  1179. /*52:*/
  1180. #line 961 "common.w"
  1181.  
  1182. switch(section_name_cmp(&first,name_len,r)){
  1183.  
  1184. case prefix:
  1185. if(!ispref){
  1186. #line 775 "common.ch"
  1187. printf(get_string(MSG_ERROR_CO52_1));
  1188. #line 967 "common.w"
  1189.  
  1190. print_section_name(r);
  1191. err_print(">");
  1192. }
  1193. else if(name_len<prefix_length(r))set_prefix_length(r,name_len);
  1194.  
  1195. case equal:return r;
  1196. case extension:if(!ispref||first<=last)
  1197. extend_section_name(r,first,last+1,ispref);
  1198. return r;
  1199. case bad_extension:
  1200. #line 782 "common.ch"
  1201. printf(get_string(MSG_ERROR_CO52_2));
  1202. #line 979 "common.w"
  1203.  
  1204. print_section_name(r);
  1205. err_print(">");
  1206. return r;
  1207. default:
  1208. #line 792 "common.ch"
  1209. printf(get_string(MSG_ERROR_CO52_3));
  1210.  
  1211. print_prefix_name(r);
  1212. printf(get_string(MSG_ERROR_CO52_4));
  1213. #line 988 "common.w"
  1214. print_section_name(r);
  1215. err_print(">");
  1216. return r;
  1217. }
  1218.  
  1219. /*:52*/
  1220. #line 920 "common.w"
  1221. ;
  1222. }
  1223.  
  1224. /*:49*//*54:*/
  1225. #line 1012 "common.w"
  1226.  
  1227. #line 812 "common.ch"
  1228. static int section_name_cmp(char**pfirst,int len,name_pointer r)
  1229.  
  1230.  
  1231.  
  1232. #line 1017 "common.w"
  1233. {
  1234. char*first= *pfirst;
  1235. name_pointer q= r+1;
  1236. #line 821 "common.ch"
  1237. char HUGE*ss;
  1238. char HUGE*s= first_chunk(r);
  1239. #line 1021 "common.w"
  1240. int c;
  1241. int ispref;
  1242. while(1){
  1243. ss= (r+1)->byte_start-1;
  1244. if(*ss==' '&&ss>=r->byte_start)ispref= 1,q= q->link;
  1245. else ispref= 0,ss++,q= name_dir;
  1246. switch(c= web_strcmp(first,len,s,ss-s)){
  1247. case equal:if(q==name_dir)
  1248. if(ispref){
  1249. #line 828 "common.ch"
  1250. *pfirst= first+(ptrdiff_t)(ss-s);
  1251. #line 1031 "common.w"
  1252. return extension;
  1253. }else return equal;
  1254. else return(q->byte_start==(q+1)->byte_start)?equal:prefix;
  1255. case extension:
  1256. if(!ispref)return bad_extension;
  1257. first+= ss-s;
  1258. #line 834 "common.ch"
  1259. if(q!=name_dir){len-= (int)(ss-s);s= q->byte_start;r= q;continue;}
  1260. #line 1038 "common.w"
  1261. *pfirst= first;return extension;
  1262. default:return c;
  1263. }
  1264. }
  1265. }
  1266.  
  1267. /*:54*//*58:*/
  1268. #line 1087 "common.w"
  1269.  
  1270. #line 871 "common.ch"
  1271. void err_print(char*s)
  1272. #line 1091 "common.w"
  1273. {
  1274. char*k,*l;
  1275. printf(*s=='!'?"\n%s":"%s",s);
  1276. if(web_file_open)/*59:*/
  1277. #line 1107 "common.w"
  1278.  
  1279. {if(changing&&include_depth==change_depth)
  1280. #line 880 "common.ch"
  1281. printf(get_string(MSG_ERROR_CO59_1),change_line);
  1282. else if(include_depth==0)printf(get_string(MSG_ERROR_CO59_2),cur_line);
  1283. else printf(get_string(MSG_ERROR_CO59_3),cur_line,cur_file_name);
  1284. #line 1112 "common.w"
  1285. l= (loc>=limit?limit:loc);
  1286. if(l>buffer){
  1287. for(k= buffer;k<l;k++)
  1288. if(*k=='\t')putchar(' ');
  1289. else putchar(*k);
  1290. putchar('\n');
  1291. for(k= buffer;k<l;k++)putchar(' ');
  1292. }
  1293. for(k= l;k<limit;k++)putchar(*k);
  1294. if(*limit=='|')putchar('|');
  1295. putchar(' ');
  1296. }
  1297.  
  1298. /*:59*/
  1299. #line 1094 "common.w"
  1300. ;
  1301. update_terminal;mark_error;
  1302. }
  1303.  
  1304. /*:58*//*61:*/
  1305. #line 929 "common.ch"
  1306.  
  1307. int wrap_up(void){
  1308. putchar('\n');
  1309. if(show_stats)print_stats();
  1310. /*62:*/
  1311. #line 1152 "common.w"
  1312.  
  1313. switch(history){
  1314. #line 953 "common.ch"
  1315. case spotless:if(show_happiness)printf(get_string(MSG_HAPPINESS_CO62));break;
  1316. case harmless_message:
  1317. printf(get_string(MSG_WARNING_CO62));break;
  1318. case error_message:
  1319. printf(get_string(MSG_ERROR_CO62));break;
  1320. case fatal_message:printf(get_string(MSG_FATAL_CO62));
  1321. #line 1160 "common.w"
  1322. }
  1323.  
  1324. /*:62*/
  1325. #line 933 "common.ch"
  1326. ;
  1327. /*90:*/
  1328. #line 1324 "common.ch"
  1329.  
  1330. #ifdef _AMIGA
  1331. if(LocaleBase){
  1332. CloseCatalog(catalog);
  1333. CloseLibrary(LocaleBase);
  1334. }
  1335. #endif
  1336.  
  1337. /*:90*/
  1338. #line 934 "common.ch"
  1339. ;
  1340. switch(history){
  1341. case harmless_message:return(RETURN_WARN);break;
  1342. case error_message:return(RETURN_ERROR);break;
  1343. case fatal_message:return(RETURN_FAIL);break;
  1344. default:return(RETURN_OK);
  1345. }
  1346. }
  1347. #line 1151 "common.w"
  1348.  
  1349. /*:61*//*64:*/
  1350. #line 976 "common.ch"
  1351. void fatal(char*s,char*t)
  1352. #line 1174 "common.w"
  1353. {
  1354. if(*s)printf(s);
  1355. err_print(t);
  1356. history= fatal_message;exit(wrap_up());
  1357. }
  1358.  
  1359. /*:64*//*65:*/
  1360. #line 984 "common.ch"
  1361. void overflow(char*t)
  1362. #line 1185 "common.w"
  1363. {
  1364. #line 991 "common.ch"
  1365. printf(get_string(MSG_FATAL_CO65),t);fatal("","");
  1366. #line 1187 "common.w"
  1367. }
  1368.  
  1369.  
  1370. /*:65*//*70:*/
  1371. #line 1246 "common.w"
  1372.  
  1373. #line 1085 "common.ch"
  1374. static void scan_args(void)
  1375. #line 1249 "common.w"
  1376. {
  1377. char*dot_pos;
  1378. char*name_pos;
  1379. register char*s;
  1380. boolean found_web= 0,found_change= 0,found_out= 0;
  1381.  
  1382. boolean flag_change;
  1383.  
  1384. while(--argc>0){
  1385. if((**(++argv)=='-'||**argv=='+')&&*(*argv+1))/*74:*/
  1386. #line 1340 "common.w"
  1387.  
  1388. {
  1389. if(**argv=='-')flag_change= 0;
  1390. else flag_change= 1;
  1391. for(dot_pos= *argv+1;*dot_pos>'\0';dot_pos++)
  1392. flags[*dot_pos]= flag_change;
  1393. }
  1394.  
  1395. /*:74*/
  1396. #line 1258 "common.w"
  1397.  
  1398. else{
  1399. s= name_pos= *argv;dot_pos= NULL;
  1400. #line 1098 "common.ch"
  1401. while(*s){
  1402. if(*s=='.')dot_pos= s++;
  1403. #ifdef _AMIGA
  1404. else if((*s=='/')||(*s==':'))dot_pos= NULL,name_pos= ++s;
  1405. #else
  1406. else if(*s=='/')dot_pos= NULL,name_pos= ++s;
  1407. #endif
  1408. else s++;
  1409. }
  1410. #line 1266 "common.w"
  1411. if(!found_web)/*71:*/
  1412. #line 1284 "common.w"
  1413.  
  1414. {
  1415. if(s-*argv>max_file_name_length-5)
  1416. /*76:*/
  1417. #line 1152 "common.ch"
  1418. fatal(get_string(MSG_FATAL_CO76),*argv);
  1419. #line 1361 "common.w"
  1420.  
  1421.  
  1422. /*:76*/
  1423. #line 1287 "common.w"
  1424. ;
  1425. if(dot_pos==NULL)
  1426. sprintf(web_file_name,"%s.w",*argv);
  1427. else{
  1428. strcpy(web_file_name,*argv);
  1429. *dot_pos= 0;
  1430. }
  1431. sprintf(alt_web_file_name,"%s.web",*argv);
  1432. sprintf(tex_file_name,"%s.tex",name_pos);
  1433. sprintf(idx_file_name,"%s.idx",name_pos);
  1434. sprintf(scn_file_name,"%s.scn",name_pos);
  1435. sprintf(C_file_name,"%s.c",name_pos);
  1436. found_web= 1;
  1437. }
  1438.  
  1439. /*:71*/
  1440. #line 1267 "common.w"
  1441.  
  1442. else if(!found_change)/*72:*/
  1443. #line 1302 "common.w"
  1444.  
  1445. {
  1446. if(strcmp(*argv,"-")==0)found_change= -1;
  1447. else{
  1448. if(s-*argv>max_file_name_length-4)
  1449. /*76:*/
  1450. #line 1152 "common.ch"
  1451. fatal(get_string(MSG_FATAL_CO76),*argv);
  1452. #line 1361 "common.w"
  1453.  
  1454.  
  1455. /*:76*/
  1456. #line 1307 "common.w"
  1457. ;
  1458. if(dot_pos==NULL)
  1459. sprintf(change_file_name,"%s.ch",*argv);
  1460. else strcpy(change_file_name,*argv);
  1461. found_change= 1;
  1462. }
  1463. }
  1464.  
  1465. /*:72*/
  1466. #line 1268 "common.w"
  1467.  
  1468. else if(!found_out)/*73:*/
  1469. #line 1315 "common.w"
  1470.  
  1471. {
  1472. if(s-*argv>max_file_name_length-5)
  1473. /*76:*/
  1474. #line 1152 "common.ch"
  1475. fatal(get_string(MSG_FATAL_CO76),*argv);
  1476. #line 1361 "common.w"
  1477.  
  1478.  
  1479. /*:76*/
  1480. #line 1318 "common.w"
  1481. ;
  1482. if(dot_pos==NULL){
  1483. sprintf(tex_file_name,"%s.tex",*argv);
  1484. sprintf(idx_file_name,"%s.idx",*argv);
  1485. sprintf(scn_file_name,"%s.scn",*argv);
  1486. sprintf(C_file_name,"%s.c",*argv);
  1487. }else{
  1488. strcpy(tex_file_name,*argv);
  1489. if(flags['x']){
  1490. if(program==cweave&&strcmp(*argv+strlen(*argv)-4,".tex")!=0)
  1491. #line 1125 "common.ch"
  1492. fatal(get_string(MSG_FATAL_CO73),*argv);
  1493. #line 1329 "common.w"
  1494.  
  1495. strcpy(idx_file_name,*argv);
  1496. strcpy(idx_file_name+strlen(*argv)-4,".idx");
  1497. strcpy(scn_file_name,*argv);
  1498. strcpy(scn_file_name+strlen(*argv)-4,".scn");
  1499. }
  1500. strcpy(C_file_name,*argv);
  1501. }
  1502. found_out= 1;
  1503. }
  1504.  
  1505. /*:73*/
  1506. #line 1269 "common.w"
  1507.  
  1508. else/*75:*/
  1509. #line 1348 "common.w"
  1510.  
  1511. {
  1512. if(program==ctangle)
  1513. #line 1139 "common.ch"
  1514. fatal(get_string(MSG_FATAL_CO75_1),"");
  1515.  
  1516. #ifdef _AMIGA
  1517. else fatal(get_string(MSG_FATAL_CO75_2),"");
  1518. #else
  1519. else fatal(get_string(MSG_FATAL_CO75_3),"");
  1520. #endif
  1521. #line 1358 "common.w"
  1522. }
  1523.  
  1524. #line 1152 "common.ch"
  1525. /*:75*/
  1526. #line 1270 "common.w"
  1527. ;
  1528. }
  1529. }
  1530. if(!found_web)/*75:*/
  1531. #line 1348 "common.w"
  1532.  
  1533. {
  1534. if(program==ctangle)
  1535. #line 1139 "common.ch"
  1536. fatal(get_string(MSG_FATAL_CO75_1),"");
  1537.  
  1538. #ifdef _AMIGA
  1539. else fatal(get_string(MSG_FATAL_CO75_2),"");
  1540. #else
  1541. else fatal(get_string(MSG_FATAL_CO75_3),"");
  1542. #endif
  1543. #line 1358 "common.w"
  1544. }
  1545.  
  1546. #line 1152 "common.ch"
  1547. /*:75*/
  1548. #line 1273 "common.w"
  1549. ;
  1550. #line 1112 "common.ch"
  1551. #if defined( __TURBOC__ )
  1552. if(found_change<=0)strcpy(change_file_name,"nul");
  1553. #elif defined( _AMIGA )
  1554. if(found_change<=0)strcpy(change_file_name,"NIL:");
  1555. #else
  1556. if(found_change<=0)strcpy(change_file_name,"/dev/null");
  1557. #endif
  1558. #line 1275 "common.w"
  1559. }
  1560.  
  1561. /*:70*//*82:*/
  1562. #line 1200 "common.ch"
  1563.  
  1564. static boolean set_path(char*ptr,char*override)
  1565. {
  1566. if(override){
  1567. if(strlen(override)>=MAXPATHLENGTH){
  1568. err_print("! Include path too long");return(0);
  1569.  
  1570. }
  1571. else strcpy(ptr,override);
  1572. }
  1573. return(1);
  1574. }
  1575.  
  1576. /*:82*//*85:*/
  1577. #line 1247 "common.ch"
  1578.  
  1579. #ifdef __TURBOC__
  1580. void far*allocsafe(unsigned long nunits,unsigned long unitsz)
  1581. {
  1582. void far*p= farcalloc(nunits,unitsz);
  1583. if(p==NULL)fatal("","! Memory allocation failure");
  1584.  
  1585. return p;
  1586. }
  1587. #endif
  1588.  
  1589.  
  1590. /*:85*/
  1591.